﻿@model ShivamEMR.Model.Domain.PatientDomain.Patient
<table id="Medical">
    <tr id="Medicaldata">
        <td id="title">
        </td>
        <td id="value">
        </td>
        <td id="notes">
        </td>
    </tr>
    <tr>
        <td>
            <table id="patientInformations">
                @foreach (var c in Model.PatientInformations)
                {
                    <tr>
                        <td>
                            <span>@c.Title</span>
                        </td>
                        <td>
                            <span>@c.Value </span>
                        </td>
                    </tr>  
                }
            </table>
        </td>
    </tr>
    <tr>
        <td>
            @Html.ActionLink("Add More..", "NewPatientInformation", "Patient", new { @class = "addPatientInformationsLink" })
        </td>
    </tr>
</table>
<div id="AddPatientInformationsDialog" title="Add Information">
</div>
<script type="text/javascript">

    var linkObj;

    function PatientInformationsSuccess(data) {
        debugger;
        if (data.Success == true) {
           createRow(data);
            $('#AddPatientInformationsDialog').dialog('close');


        }
        else {
            $("#update-message").html(data.ErrorMessage);
            $("#update-message").show();
        }
    }

    function createRow(objectData) {
        // create row node
         var table = document.getElementById("Medical");
         for (var i = 0; i < 3; i++)
        {
         var row = document.createElement('tr');
         var col = document.createElement('td');
           switch(i)
           {
               case 0:
                   col.innerHTML = objectData.Object.Title;
                   break;
               case 1:
                   col.innerHTML = objectData.Object.Notes;
                   break;
               case 2:
                   col.innerHTML = objectData.Object.Value;
                   break;    

           }
            row.appendChild(col);
             table.appendChild(row); 
        }
         // create column node
       // var col2 = document.createElement('td'); // create second column node
        // append first column to row
       // row.appendChild(col2); // append second column to row
        //col.innerHTML = "qwe"; // put data in first column
       // col2.innerHTML = "rty"; // put data in second column
       // find table to append to
       // append row to table
    }
    $(function () {
        $(".addPatientInformationsLink").button();

        $('#AddPatientInformationsDialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            modal: true,
            buttons: {
                "Add": function () {
                    $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                    $("#updatePatientInformationsForm").submit();
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".addPatientInformationsLink").click(function () {
            //change the title of the dialog
            linkObj = $(this);
            var dialogDiv = $('#AddPatientInformationsDialog');
            var viewUrl = linkObj.attr('href');
            $.get(viewUrl, function (data) {
                dialogDiv.html(data);
                //validation
                var $form = $("#updatePatientInformationsForm");
                // Unbind existing validation
                $form.unbind();
                $form.data("validator", null);
                // Check document for changes
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                //open dialog
                dialogDiv.dialog('open');
            });
            return false;
        });

    });


    


        

 
    
</script>
